﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Admin/Master/Admin.Master" AutoEventWireup="true"
    CodeBehind="RoomStatusSet.aspx.cs" Inherits="Besture.UI.RoomStatusSet" %>

<%@ Register Src="~/Admin/Control/RoomUserControl.ascx" TagPrefix="cms" TagName="RoomUserControl" %>
<asp:Content ID="Content1" ContentPlaceHolderID="Head" runat="server">
    <link href="/admin/Themes/Room/css/Common.css" rel="stylesheet" />
    <link href="/admin/Themes/Room/css/style.css" rel="stylesheet" />
    <script src="/admin/Themes/Js/jquery-1.7.1.min.js"></script>
    <script src="/admin/Themes/Js/jquery.validate.js"></script>
    <style type="text/css">
        .li-roomCount {
            color: #000000 !important;
            font-size: 14px !important;
        }

        .li-roomCount1 {
            color: #9A9A9A !important;
            font-size: 14px !important;
            height: 43px;
            line-height: 43px;
            font-weight: bold;
        }
        .pop-box {
            height: 220px !important; 
            }
    </style>
    <script type="text/javascript">
        /** 日历效果 start lyg **/
        var BookingCalendar = function (data) {
            var onSelected;
            var selection = [];
            var calendar = $("#calendar");
            var selectStart = false;
            var ctrl = false;

            if (data) {
                if (data.onSelected)
                    onSelected = data.onSelected;
                if (data.container)
                    calendar = $(data.container); //$("#calendar");
            }

            if (!calendar.length) return;

            $("body,html").keydown(function (e) {
                if (e.keyCode == 17) {
                    ctrl = true;
                }

            }).keyup(function (e) {
                if (e.keyCode == 17) {
                    ctrl = false;
                    //松开ctrl时，判断是否有选中并回调
                    if (selection != null && selection.length > 0 && onSelected)
                        onSelected(selection);
                }
            });

            calendar.on("mousedown", "td:not('.disabled')", function (e) {
                if (e.which == 1) {
                    var _day = $(this);
                    preSelectStart(_day);
                }
            }).on("mouseover", "td:not('.disabled')", function () {
                var _day = $(this);
                preSelect(_day);
            }).on("mouseup", "td:not('.disabled')", function (e) {
                selectEnd();

                if (!ctrl && selection != null && selection.length > 0 && onSelected) {
                    onSelected(selection);
                }
            });

            $("html,body").mouseup(function (e) {
                if (e.which == 1) {
                    if (!selectStart) return;
                    selectEnd();
                    if (!ctrl) {
                        if (onSelected) onSelected(selection);
                    }
                }
            });

            function preSelectStart(jObj) {
                var childrenDiv = jObj.children();
                if (ctrl && (childrenDiv.is(".pre-select") || childrenDiv.is(".selected"))) {
                    clear(jObj);
                } else {
                    selectStart = true;
                    preSelect(jObj);
                }
            }

            function preSelect(_jCurrentDate) {
                if (selectStart) {
                    _jCurrentDate.children().addClass("pre-select");
                }
            }

            function selectEnd() {
                $(".pre-select", calendar).each(function () {
                    var _this = $(this);
                    select(_this.parent());
                });
                selectStart = false;
            }

            function select(obj) {
                var date = getDateAttr(obj);
                var index = $.inArray(date, selection);
                if (index == -1) {
                    selection.push(date);
                }

                obj.children().addClass("selected").removeClass("pre-select");
            }

            this.clearAll = function () {
                selection = [];
                $("td", calendar).children().removeClass("selected").removeClass("pre-select");
            }

            function clear(jObj) {
                var date = getDateAttr(jObj);
                var index = $.inArray(date, selection);
                if (index > -1) selection.splice(index, 1);

                jObj.children().removeClass("selected").removeClass("pre-select");
            }

            function getDate(obj) {
                return new Date(getDateAttr(obj));
            }

            function getDateAttr(obj) {
                return $(obj).attr("date");
            }
        }
        /** 日历效果 end lyg **/

        //日历的展开收缩操作
        function toggleType(obj, isTitle) {
            var roomTypeContainer = $(obj).parent().parent().find("div.room-price-bd");
            if (roomTypeContainer.is(":hidden")) {
                if (!isTitle) {
                    $(obj).addClass("btn-unfold");
                    $(obj).removeClass("btn-fold");
                    $(obj).find("label").html("展开 ");
                } else {
                    $(obj).next("a").find("label").html("收起 ");
                }
                roomTypeContainer.show();
            } else {
                if (!isTitle) {
                    $(obj).addClass("btn-fold");
                    $(obj).removeClass("btn-unfold");
                    $(obj).find("label").html("收起 ");
                } else {
                    $(obj).next("a").find("label").html("展开 ");
                }
                roomTypeContainer.hide();
            }
        } 

        function GetQuery() {

            //上一月份
            $('#prevMonth').click(function () {
                $("#<%= hidColendarMonth.ClientID %>").val(1);
                $("#<%= btnSeach.ClientID %>").click();
            });


            //下一月份
            $('#benMonth').click(function () {
                $("#<%= hidColendarMonth.ClientID %>").val(0);
                $("#<%= btnSeach.ClientID %>").click();
            });

            //下一月份
            $('#nextMonth').click(function () {
                $("#<%= hidColendarMonth.ClientID %>").val(2);
                $("#<%= btnSeach.ClientID %>").click();
            });

            /** 点击【查询】按钮后 触发事件 **/
            $(".btn.btn-query").click(function () {
                //获取选中房型id
                var vRoomId = $("#ctl00_Content_HotelUserControl_ddlRoom").val();
                var vHotels = $("#ctl00_Content_HotelUserControl_ddlHotels").val();
                if (vHotels.length < 1) {
                    alert("请选择酒店");
                    return;
                }
                if (vRoomId > 0) {
                    $("#<%= hidID.ClientID %>").val("1|" + vRoomId);
                } else {
                    //获取选中酒店id ;0表示显示酒店全部房型 反之1某一个房型
                    $("#<%= hidID.ClientID %>").val("0|" + vHotels);
                }
                $("#<%= btnSeach.ClientID %>").click();
            });
        }

        function GetInLoadCalendar() { 
     
            $(".calendar.clearfix.room-price-bd").each(function (e) {
                var _this = $(this);
                    var rID = _this.find(".yearMonth i").text(); //房型id
                    var rLowPrice = _this.find(".yearMonth span").text(); //低价

                    var cal = new BookingCalendar({
                        container: _this,
                        onSelected: function(selection) {
                            var pTitle = selection.toString();
                            var pText = pTitle.length < 11 ? pTitle : pTitle.substring(0, 10) + "...";
                            //弹窗
                            $("#txt_box_LowPrice").text(rLowPrice);
                            $(".mask").height($(".editPage").height()).show();
                            $(".pop-box").show().children("a").attr("title", rID + "|" + pTitle).text(pText);
                            $(".pop-btn").removeData("calender").data("calender", cal);
                        }
                    });
            });
        }
         
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="Content" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <input type="hidden" id="hidBreakfast" value="0" runat="server" />
    <input type="hidden" id="hidRoom" value="" runat="server" />
    <input type="hidden" id="hidID" value="" runat="server" />
    <input type="hidden" id="hidColendarMonth" value="0" runat="server" />
    <%--hidColendarMonth : 0表示当前月份; 1表示前月份; 2表示前月份--%>
    <div class="editPage">
        <ul class="tab">
            <li class="on" onclick=" setTab(this, 0) "><a href="javascript:void(0)" title="房态维护">房态维护</a></li>
            <li onclick=" setTab(this, 1) "><a href="javascript:void(0)" title="批量修改房态">批量修改房态</a></li>
        </ul>
        <div class="tab-ct-wrap">
            <div class="tab1">
                <cms:RoomUserControl runat="server" ID="HotelUserControl" />
                <asp:UpdatePanel ID="UpdatePanel2" runat="server">
                    <ContentTemplate>
                        <span style="display:none ">
                            <asp:Button ID="btnSeach" runat="server" Text="查询" UseSubmitBehavior="false" OnClick="BtnSeachClick" />
                        </span>
                        <%--20150507 lyg start 日历--%>
                        <div id="calendarWrap" runat="server" class="calendar-wrap">
                            <!--说明-->
                            <div class="sec-room-guide clearfix">
                                <ul class="ui-guide-info clearfix">
                                    <li>颜色说明：</li>
                                    <li><i class="room-color room-blues" style="background-color: #fff !important;"></i>
                                        有房</li>
                                    <li><i class="room-color room-orange" style="background-color: #fb988c !important;"></i>客满</li>
                                    <li><i class="room-color room-orange" style="background-color: #fbddbb !important;"></i>限量</li>
                                    <li>标识说明：</li>
                                    <li><i class="room-icon icon-breakfast" style="height: 16px; width: 18px; background: url(/admin/Themes/Room/images/roomico.png) -185px -109px;"></i>无房价/不可订</li>
                                </ul>
                                <ul class="ui-guide-info clearfix" style="float: right;">
                                    <li><a href="javascript:void(0);" id="prevMonth" class="ui-link">&lt; 前一月</a> &nbsp;&nbsp;&nbsp;&nbsp;
                                        <a href="javascript:void(0);" id="benMonth" class="ui-link">本月</a> &nbsp;&nbsp;&nbsp;&nbsp;
                                        <a href="javascript:void(0);" id="nextMonth" class="ui-link">后一月&gt;</a> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                        当前显示&nbsp;&nbsp;<input type="text" runat="server" disabled="disabled"  style="width: 20px;" id="txtMonth" />&nbsp;&nbsp;月份 </li>
                                </ul>
                            </div>
                            <!--日历-->
                            <asp:Repeater ID="rpRoom" runat="server">
                                <ItemTemplate>
                                    <div class="sec-room-price">
                                        <div class="room-price-hd">
                                            <h3 class="ui-room-title" onclick=" toggleType(this, true) ">
                                                <span>
                                                    <%#Eval("RoomName") %></span></h3>
                                            <a href="javascript:void(0);" onclick=" toggleType(this) " class="btn-fold">
                                                <label>
                                                    收起
                                                </label>
                                                <i class="icon-arrows"></i></a>
                                        </div>
                                        <div class="calendar clearfix  room-price-bd">
                                            <div class="yearMonth">
                                                <%= IDataNow.Year %>年<%= IDataNow.Month %>月 <i style="display: none">
                                                    <%#Eval("ID") %></i> <span style="display: none">
                                                        <%#Eval("LowPrice") %></span>
                                            </div>
                                            <table>
                                                <thead>
                                                    <tr>
                                                        <th>周日
                                                        </th>
                                                        <th>周一
                                                        </th>
                                                        <th>周二
                                                        </th>
                                                        <th>周三
                                                        </th>
                                                        <th>周四
                                                        </th>
                                                        <th>周五
                                                        </th>
                                                        <th>周六
                                                        </th>
                                                    </tr>
                                                </thead>
                                                <tbody>
                                                    <%# GetCalendarData(Convert.ToInt32(Eval("ID"))) %>
                                                <tbody>
                                            </table>
                                        </div>
                                    </div>
                                </ItemTemplate>
                            </asp:Repeater>
                        </div>
                        <%--20150507 lyg end 日历--%>
                        <!--遮罩-->
                        <div class="mask" style="height: auto; width: 1122px;">
                        </div>
                    </ContentTemplate>
                    <Triggers>
                        <asp:PostBackTrigger ControlID="btnSeach" />
                    </Triggers>
                </asp:UpdatePanel>
            </div>
            <div class="tab1" style="display: none;">
                <cms:BatchModifyStatusControl runat="server" ID="BatchModifyPricesControl1" />
            </div>
        </div>
        <!--弹窗-->
        <div class="pop-box">
            <a href="javascript:void(0);" title=""></a>
            <div>
                <span>修改房态：</span>
                <asp:RadioButton ID="rabNotUpdate" Text="不做修改" Checked="True" GroupName="Room" runat="server" />
                <asp:RadioButton ID="rabHouse" Text="有房" GroupName="Room" runat="server" />
                <asp:RadioButton ID="rabTension" Text="限量" GroupName="Room" runat="server" />
                <asp:RadioButton ID="rabFullHouse" Text="客满" GroupName="Room" runat="server" />
            </div>
            <div class="divRadio">
                <span>设置房间数量：</span>
                <asp:RadioButton ID="rabNumber" Text="不做修改" Checked="True" GroupName="Number" runat="server" />
                <asp:RadioButton ID="rabAddRoom" Text="增加" GroupName="Number" runat="server" />
                <asp:TextBox runat="server" ID="txtAddNumber" CssClass="number"  MaxLength="2" Width="20"></asp:TextBox>间
                <asp:RadioButton ID="rabCutBack" Text="减少" GroupName="Number" runat="server" />
                <asp:TextBox runat="server" ID="txtCutBackNumber" MaxLength="2" Width="20"></asp:TextBox>间
            </div>
            <div style="display:none" >
                <span>限量售卖：</span>
                <asp:TextBox runat="server" ID="txtLimitedSale" CssClass="required number"  Text="0" Width="50"></asp:TextBox>
            </div>
            <div>
                <asp:Button ID="btnSavePrice" class="pop-btn btn-ok" OnClientClick="return BtnOnClick();"
                    runat="server" Text="确定" OnClick="BtnSavePriceClick" />
                <a href="javascript:void(0);" class="pop-btn btn-cancel">取消</a>
            </div>
        </div>
    </div>
    <script type="text/javascript">
         

        function BtnOnClick() {
            //获取 房型id 和 日期 
            //增加 
            if ($("#ctl00_Content_rabAddRoom").attr("checked") == "checked") {
                if (parseInt($("#<%=txtLimitedSale.ClientID%>").val()) > parseInt($("#ctl00_Content_txtAddNumber").val())) {
                    alert("限量售卖房间数 必须小于 设置房间数量" + $("#ctl00_Content_txtAddNumber").val());
                    $("#<%=txtLimitedSale.ClientID%>").focus();
                    return false;
                }
                if ($("#ctl00_Content_txtAddNumber").val().length<1) {
                    alert("请输入增加的房间数！");
                    $("#ctl00_Content_txtAddNumber").focus();
                    return false;
                }
            }
            if ($("#ctl00_Content_rabCutBack").attr("checked") == "checked"
                && $("#ctl00_Content_txtCutBackNumber").val().length < 1) {
                //减少
                alert("请输入减少的房间数！");
                $("#ctl00_Content_txtCutBackNumber").focus();
                return false;
             }
            //else {
            //    var cal = $(this).data("calender");
            //    cal.clearAll();
            //    return true;
            //}
            return true;
        }

        $(function () {

            $(".divRadio input[type='radio']").click(function () {
                $(this).parents("div").next("div").css("display", "none");
                if ($(this).val() == "rabAddRoom") {
                    $(this).parents("div").next("div").css("display", "");
                }
            });
            $("table thead tr th").click(function() {
                var v = $(this).index();
                $(this).parents("thead").next().find("td").eq(v).each(function () {
                   $(this).addClass("div:hover ");
                });

            });

            //弹出框 取消 事件 
            $(".pop-btn.btn-cancel").click(function () {
                var cal = $(this).data("calender");
                cal.clearAll();
                $(".pop-box").hide();
                $(".mask").hide();
            });

            //弹出框 确定 事件
            $(".pop-btn.btn-ok").click(function () {
                var vhotels = $(this).parents(".pop-box").find("a").attr("title");
                $("#<%=hidRoom.ClientID %>").val(vhotels);
            });

            $("#ctl00_Content_txtAddNumber").focus(function () {
                $("#ctl00_Content_rabAddRoom").attr("checked", true);
            });
            $("#ctl00_Content_txtCutBackNumber").focus(function () {
                $("#ctl00_Content_rabCutBack").attr("checked", true);
            });

            GetQuery();//初始化分页事件
         
            GetInLoadCalendar(); //日历 each  初始化 

          
        });

    </script>
</asp:Content>
